package com.augurit.gzcgwsp.ssylb.convert;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.dozer.DozerBeanMapper;

import com.augurit.gzcgwsp.ssgd.web.form.YwRqSsgdSqbForm;
import com.augurit.gzcgwsp.ssylb.entity.YwRqRqssylb;
import com.augurit.gzcgwsp.ssylb.web.form.YwRqRqssylbForm;

public class YwRqRqssylbConvertor {
	public static YwRqRqssylbForm convertVoToForm(YwRqRqssylb entity) {
		if(entity != null) {
			YwRqRqssylbForm form = new DozerBeanMapper().map(entity, YwRqRqssylbForm.class);
			return form;
		}else
			return null;
	}
	
	public static void convertFormToVo(YwRqRqssylbForm form, YwRqRqssylb entity) {
		if(entity != null && form != null) {
			entity.setSsylbid(form.getId());
			if(form.getSsmc() != null && form.getSsmc().trim().length() > 0)
				entity.setSsmc(form.getSsmc().trim());
			if(form.getSsaddress() != null && form.getSsaddress().trim().length() > 0)
				entity.setSsaddress(form.getSsaddress().trim());
			if(form.getSslb() != null && form.getSslb().trim().length() > 0)
				entity.setSslb(form.getSslb().trim());
			entity.setQyjyxkid(form.getQyjyxkid());
		}
	}
	
	public static List<YwRqRqssylbForm> convertVoListToFormList(List<YwRqRqssylb> ywRqRqssylbList) {
		if(ywRqRqssylbList != null && ywRqRqssylbList.size() > 0) {
			List<YwRqRqssylbForm> ywRqRqssylbFormList = new ArrayList();
			for(int i=0; i<ywRqRqssylbList.size(); i++) {
				ywRqRqssylbFormList.add(convertVoToForm(ywRqRqssylbList.get(i)));
			}
			return ywRqRqssylbFormList;
		}
		return null;
	}
	
	public static List<Map> convertVoListToMapList(List<YwRqRqssylb> ywRqRqssylbList) {
		if(ywRqRqssylbList != null && ywRqRqssylbList.size() > 0) {
			List<Map> mapList = new ArrayList();
			for(int i=0; i<ywRqRqssylbList.size(); i++) {
				YwRqRqssylb entity = ywRqRqssylbList.get(i);
				Map<String, String> map = new HashMap();

				map.put("id", entity.getSsylbid() == null ? "" : entity.getSsylbid().toString());
				map.put("ssmc", entity.getSsmc());
				map.put("ssaddress", entity.getSsaddress());
				map.put("sslb", entity.getSslb());
				map.put("qyjyxkid", entity.getQyjyxkid() == null ? "" : entity.getQyjyxkid().toString());
				
				mapList.add(map);
			}
			return mapList;
		}
		return null;
	}
	
	public static List<YwRqRqssylb> convertFormListToVoList(List<YwRqRqssylbForm> ywRqRqssylbFormList) {
		if(ywRqRqssylbFormList != null && ywRqRqssylbFormList.size() > 0) {
			List<YwRqRqssylb> ywRqRqssylbList = new ArrayList();
			for(int i=0; i<ywRqRqssylbFormList.size(); i++) {
				YwRqRqssylb ywRqRqssylb = new YwRqRqssylb();
				convertFormToVo(ywRqRqssylbFormList.get(i), ywRqRqssylb);
				ywRqRqssylbList.add(ywRqRqssylb);
			}
			return ywRqRqssylbList;
		}
		return null;
	}
}